<template>
  <!-- 精选题库 -->
  <div class='container'>
    <keep-alive>
      <question-bank
      :isShow="true"
      :list="questionsList"
      :counts="counts"
      :isFixed="true"
      :pagination="pagination"
      :titleDetails="titleDetails"
      @delTitle="delTitle"
      @preview="preview"
      @pageChange="pageChange"
      @searchTopic="searchTopic"
      @updateList="updateList"
      />
    </keep-alive>
  </div>
</template>

<script>
import questionBank from '../components/question-bank.vue'
import { choice, remove, detail } from '@/api/hmmm/questions'
// import { direction, chkType } from '@/api/hmmm/constants'
export default {
  components: {
    questionBank
  },
  data () {
    return {
      pagination: {
        // 当前页
        page: 1,
        // 当前页显示总数
        pagesize: 10
      },
      questionsList: [],
      counts: 0,
      titleDetails: {}
    }
  },
  methods: {
    // 获取精选题库列表
    async getChoiceList (data) {
      const { counts, items } = (await choice(data)).data
      this.counts = counts
      this.questionsList = items
    },
    pageChange (data) {
      this.getChoiceList(data)
    },
    searchTopic (data) {
      if (!data?.subjectID) return this.getChoiceList()
      this.getChoiceList(data)
    },
    // 删除题目
    delTitle (data) {
      this.$confirm('此操作将永久删除该题目，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const { data: { success } } = await remove(data)
        if (!success) return this.$message.error('删除精选失败')
        this.$message.success('删除精选成功')
        this.getChoiceList()
      }).catch(() => {
        this.$message.info('已取消操作')
      })
    },
    // 预览弹层
    async preview (row) {
      const { data } = await detail(row)
      this.titleDetails = data
    },
    updateList () {
      this.getChoiceList()
    }
  },
  created () {
    this.getChoiceList()
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .dashboard-container {
  padding: 20px;
}
</style>
